package com.ailink.basic.reflect;

/**
 * Created by Administrator on 2018/8/6
 */
public class ClassDemo1 {

    public static void main(String[] args) {
        Food food = new Food();

        Class c1 = Food.class;

        Class c2 = food.getClass();

        System.out.println(c1 == c2);

        Class c3 = null;
        try {
            c3 = Class.forName("com.ailink.basic.reflect.Food");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println(c2 == c3);

        try {
            Food food1 = (Food) c1.newInstance();
            food1.print();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

class Food {
    void print() {
        System.out.println("food");
    }
}
